import React from 'react'
import {FormattedMessage} from 'react-intl';
import {withRouter } from 'react-router'
import Input from '../base/Input.js'
// import Checkbox from '../base/Checkbox.js'
// import validate from '../base/Validate.js'
import {newPeriod} from '../../actions/periodAction.js'
const PeriodForm = withRouter(
	React.createClass({
		getInitialState() {
			return {
				form_data: {
					name: '',
					amount: '',
					idealens: true,
					test: false
				}
			}
		},
		handleSubmit(event) {
			event.preventDefault()
			$(this.refs.formbox).find('input,textarea').trigger('focus').trigger('blur');
			newPeriod(this.state.form_data,this.props.router)
		},
		handleChange(targetData) {
			var form_data = this.state.form_data;
			form_data[targetData.name] = targetData.value;
			this.setState({
				form_data: form_data
			})
			
		},
		render(){
			let v1 = {data : {}};
					v1.data[validate.notempty] = <FormattedMessage id='not empty'description='为空验证'defaultMessage='Hello, Howard'/>;
					// v1.minLengthByte        = {min:5,message:'至少5个字节'}
					// v1.maxLengthByte        = {max:10,message:'不超过10个字节'}
					v1.minLengthChar           = {min:5,message:'至少5个字节'}
					v1.maxLengthChar           = {max:10,message:'不超过10个字节'}
			return(
				<div>
					<h2>新增合同期限</h2>
					<form className="form-horizontal" ref='formbox'>
					  <div className="form-group">
					    <label  className="col-sm-2 control-label">名称1</label>
					    <div className="col-sm-10">
					      <Input 
					      		placeholder="请输入名称" 
					      		validate={v1} 
					      		type='text' 
					      		onChange={this.handleChange} 
					      		data-target="name"
					      	/>
					    </div>
					  </div>
					  <div className="form-group">
					    <label  className="col-sm-2 control-label">月份数</label>
					    <div className="col-sm-10">
					      <Input placeholder="请输入月份数"  type='text' onChange={this.handleChange} data-target="amount"/>
					    </div>
					  </div>

					  <div className="form-group">
					    <div className="col-sm-offset-2 col-sm-10">
					      <button type="submit" className="btn btn-default" onClick={this.handleSubmit}>保存</button>
					    </div>
					  </div>
					</form>
				</div>
			)
		}
	})
)
export default PeriodForm

